package co.kr.bettersoft.carrotmerchantmobile.adapter;

import java.util.List;

import co.kr.bettersoft.carrotmerchantmobile.activity.R;
import co.kr.bettersoft.carrotmerchantmobile.domain.CheckMileageMileage;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
//import android.widget.ImageView;
import android.widget.TextView;
/*
 * 가맹점용  고객 마일리지 목록 아답터 -- 동적 데이터를 화면 리스트에 세팅
 * 
 *   마일리지 / 아이디 / 최근이용일자 / 등록일자		 List<CheckMileageMileage>
 */
public class MileageListAdapter extends BaseAdapter {
	private Context context;
	private final List<CheckMileageMileage> entries;
 
	public MileageListAdapter(Context context, List<CheckMileageMileage> entriesFn) {		
		this.context = context;
		this.entries = entriesFn;
	}
 
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View listView;
		if (convertView == null) {
			listView = new View(context);
			listView = inflater.inflate(R.layout.main_mileage_list, null);
		} else {
			listView = (View) convertView;
		}
 
		// set value into textview
		TextView textView1 = (TextView) listView.findViewById(R.id.customer_mileage);
		textView1.setText(((CheckMileageMileage)entries.get(position)).getCustomerMileage());

		TextView textView2 = (TextView) listView.findViewById(R.id.customer_id);
		String tempPhoneNumber = ((CheckMileageMileage)entries.get(position)).getPhoneNumber();
		if(tempPhoneNumber.length()>0){					// 전번이 있으면 전번으로 출력
			textView2.setText(tempPhoneNumber);
		}else{											// 전번이 없으면 아이디로 출력
			textView2.setText(((CheckMileageMileage)entries.get(position)).getCustomerId());
		}

		TextView textView3 = (TextView) listView.findViewById(R.id.customer_update_date);
		textView3.setText(context.getString(R.string.recent_update)+" : "+((CheckMileageMileage)entries.get(position)).getLastUpdateDate());
//		TextView textView4 = (TextView) listView.findViewById(R.id.customer_register_date);
//		textView4.setText(context.getString(R.string.register_date)+"         : "+((CheckMileageMileage)entries.get(position)).getRegisterDate());

		return listView;
	}
 
	@Override
	public int getCount() {
		return entries.size();
	}
 
	@Override
	public Object getItem(int position) {
		return null;
	}
 
	@Override
	public long getItemId(int position) {
		return 0;
	}
 
}